//-----------------------------------------------------------------------
// <copyright file="tblImportTransactionDAO.cs" company="Scb">
//     Copyright ? Scb. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using Robot.Entities;
using Scb.Framework;
using Scb.Framework.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Robot.Data
{
  public class tblImportTransactionDAO : tblImportTransactionDAOBase
  {
    public tblImportTransactionDAO()
    {
    }

    public virtual void UpdatetblImportTransactionStatus(tblImportTransaction tblImportTransaction)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionUpdateStatus");

        database.AddInParameter(dbCommand, "@ID", DbType.Guid, tblImportTransaction.ID);
        database.AddInParameter(dbCommand, "@Status", DbType.Int32, tblImportTransaction.Status);

        DataAccessHelper.ExecuteNonQuery(database, dbCommand);
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessUpdatetblImportTransactionException, ex);
      }
    }

     public virtual void UpdatetblImportTransactionRule(tblImportTransaction tblImportTransaction)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionUpdateRule");

        database.AddInParameter(dbCommand, "@ID", DbType.Guid, tblImportTransaction.ID);
        database.AddInParameter(dbCommand, "@Rule1", DbType.Int32, tblImportTransaction.Rule1);
        database.AddInParameter(dbCommand, "@Rule2", DbType.Int32, tblImportTransaction.Rule2);
        database.AddInParameter(dbCommand, "@Rule3", DbType.Int32, tblImportTransaction.Rule3);
        database.AddInParameter(dbCommand, "@Rule4", DbType.Int32, tblImportTransaction.Rule4);
        database.AddInParameter(dbCommand, "@Rule5", DbType.Int32, tblImportTransaction.Rule5);
        database.AddInParameter(dbCommand, "@Exception", DbType.AnsiString, tblImportTransaction.Exception);

        DataAccessHelper.ExecuteNonQuery(database, dbCommand);
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessUpdatetblImportTransactionException, ex);
      }
    }

    public virtual tblImportTransactionCollection GettblImportTransactionByFileID(Guid Fileid)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionGetByFileID");

        database.AddInParameter(dbCommand, "@FileID", DbType.Guid, Fileid);

        tblImportTransactionCollection tblImportTransactionCollection = new tblImportTransactionCollection();
        using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
        {
          while (reader.Read())
          {
            tblImportTransaction tblImportTransaction = CreatetblImportTransactionFromReader(reader);
            tblImportTransactionCollection.Add(tblImportTransaction);
          }
          reader.Close();
        }
        return tblImportTransactionCollection;
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessGettblImportTransactionException, ex);
      }
    }

    public virtual tblImportTransactionCollection GetImportTransactionByCreatedDate(DateTime fromDate, DateTime toDate, string peoplewise)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionGetByCreatedDate");

        database.AddInParameter(dbCommand, "@FromDate", DbType.DateTime, fromDate);
        database.AddInParameter(dbCommand, "@ToDate", DbType.DateTime, toDate);
        database.AddInParameter(dbCommand, "@Peoplewise", DbType.AnsiString, peoplewise);
        
        tblImportTransactionCollection tblImportTransactionCollection = new tblImportTransactionCollection();
        using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
        {
          while (reader.Read())
          {
            tblImportTransaction tblImportTransaction = CreatetblImportTransactionFromReader(reader);
            tblImportTransactionCollection.Add(tblImportTransaction);
          }
          reader.Close();
        }
        return tblImportTransactionCollection;
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessGettblImportTransactionException, ex);
      }
    }

    public virtual tblImportTransactionCollection GetImportTransactionByCreatedDateStatus(DateTime fromDate, DateTime toDate, int status, string peoplewise)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionGetByCreatedDateStatus");

        database.AddInParameter(dbCommand, "@FromDate", DbType.DateTime, fromDate);
        database.AddInParameter(dbCommand, "@ToDate", DbType.DateTime, toDate);
        database.AddInParameter(dbCommand, "@Status", DbType.Int32, status);
        database.AddInParameter(dbCommand, "@Peoplewise", DbType.AnsiString, peoplewise);
       

        tblImportTransactionCollection tblImportTransactionCollection = new tblImportTransactionCollection();
        using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
        {
          while (reader.Read())
          {
            tblImportTransaction tblImportTransaction = CreatetblImportTransactionFromReader(reader);
            tblImportTransactionCollection.Add(tblImportTransaction);
          }
          reader.Close();
        }
        return tblImportTransactionCollection;
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessGettblImportTransactionException, ex);
      }
    }

    public virtual tblImportTransactionCollection GetImportTransactionUnSubmitByCreatedDate(DateTime fromDate, DateTime toDate, string peoplewise)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionUnSubmitGetByCreatedDate");

        database.AddInParameter(dbCommand, "@FromDate", DbType.DateTime, fromDate);
        database.AddInParameter(dbCommand, "@ToDate", DbType.DateTime, toDate);
        database.AddInParameter(dbCommand, "@Peoplewise", DbType.AnsiString, peoplewise);
       

        tblImportTransactionCollection tblImportTransactionCollection = new tblImportTransactionCollection();
        using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
        {
          while (reader.Read())
          {
            tblImportTransaction tblImportTransaction = CreatetblImportTransactionFromReader(reader);
            tblImportTransactionCollection.Add(tblImportTransaction);
          }
          reader.Close();
        }
        return tblImportTransactionCollection;
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessGettblImportTransactionException, ex);
      }
    }

    public virtual tblImportTransactionCollection GetImportTransactionSubmited(DateTime fromDate, DateTime toDate)
    {
      try
      {
        Database database = DatabaseFactory.CreateDatabase();
        DbCommand dbCommand = database.GetStoredProcCommand("_sptblImportTransactionGetSubmit");

        database.AddInParameter(dbCommand, "@FromDate", DbType.DateTime, fromDate);
        database.AddInParameter(dbCommand, "@ToDate", DbType.DateTime, toDate);
       

        tblImportTransactionCollection tblImportTransactionCollection = new tblImportTransactionCollection();
        using (IDataReader reader = DataAccessHelper.ExecuteReader(database, dbCommand))
        {
          while (reader.Read())
          {
            tblImportTransaction tblImportTransaction = CreatetblImportTransactionFromReader(reader);
            tblImportTransactionCollection.Add(tblImportTransaction);
          }
          reader.Close();
        }
        return tblImportTransactionCollection;
      }
      catch (Exception ex)
      {
        // log this exception
        Logger.Error(ex);
        // wrap it and rethrow
        throw new DataAccessException(SR.DataAccessGettblImportTransactionException, ex);
      }
    }

  }
}
